#include "xftp_task.hpp"
#include "events_cb.hpp"


#include <glog/logging.h>

#include <event2/buffer.h>
#include <event2/bufferevent.h>

#include <boost/xpressive/xpressive_dynamic.hpp>
xftp_task::xftp_task(/* args */)
{
}

xftp_task::~xftp_task()
{
}
void xftp_task::set_event_callback(struct bufferevent *buffer)
{
    bufferevent_setcb(buffer,events_cb::read_cb,0,events_cb::event_cb,this);
    bufferevent_enable(buffer,EV_READ|EV_WRITE);
}
void xftp_task::recv_cmd(std::string msg)
{
    
    if(!m_cmd_task|| !m_cmd_task->recv_bffer)  // 缓冲区或者文件描述符集合为空的时候
    {
        VLOG(0)<<"m_cmd_task m_cmd_task->recv_buffer = error";
        return;
    }
    if(msg[msg.size()-1]!='\n')
    {
        msg +='\r\n';
    }
    VLOG(0)<<"recv_cmd recv msg = "<<msg;
    bufferevent_write(m_cmd_task->recv_bffer,msg.c_str(),msg.size());
}
bool xftp_task::check_ip(const char *ip)
{
    boost::xpressive::cregex reg_ip = boost::xpressive::cregex::compile("(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])"); 
    return boost::xpressive::regex_match(ip,reg_ip);
}